<?php
/**
 * Модель comment
 * 
 * Класс модели
 * @author Anton Zavidov
 * @package myLiveShop
 */

/**
 * Модель comment
 *
 */
class ModelComment extends Model {
	
	const DELETED = '[DELETED]';
    const TABLE				= 'comment';
	const F_COMMENT_ID  	= 'comment_id';
	const F_PARENT_ID  	= 'parent_id';
	const F_USER_ID  	= 'user_id';
	const F_MODEL_ID  	= 'model_id';
	const F_MODEL  	= 'model';
	const F_CREATED  	= 'created';
	const F_DESCRIPTION  	= 'description';
	const F_LANG_ID  	= 'lang_id';
			
	public function __construct($className=null){
		parent::__construct(__CLASS__);
		$this->name='comment';
		$this->id_field=array(self::F_COMMENT_ID);
		$this->fields=array(
		self::TABLE.DOT.self::F_COMMENT_ID=> new Field($this,self::F_COMMENT_ID,self::TABLE,array(
				'auto'=>true,
				'important'=>true,
				'lenght'=>11)),
		self::TABLE.DOT.self::F_PARENT_ID=> new Field($this,self::F_PARENT_ID,self::TABLE,array(
				'lenght'=>11,
				'join_table'=>'comment')),
		self::TABLE.DOT.self::F_USER_ID=> new Field($this,self::F_USER_ID,self::TABLE,array(
				'lenght'=>11,
				'join_table'=>'user')),
		self::TABLE.DOT.self::F_MODEL_ID=> new Field($this,self::F_MODEL_ID,self::TABLE,array(
				'important'=>true,
				'lenght'=>11)),
		self::TABLE.DOT.self::F_MODEL=> new Field($this,self::F_MODEL,self::TABLE,array(
				'important'=>true,
				'lenght'=>20,
				'type'=>Field::TYPE_STRING)),
		self::TABLE.DOT.self::F_CREATED=> new Field($this,self::F_CREATED,self::TABLE,array(
				'important'=>true,
				'auto'=>true,
				'type'=>Field::TYPE_DATETIME)),
		self::TABLE.DOT.self::F_DESCRIPTION=> new Field($this,self::F_DESCRIPTION,self::TABLE,array(
				'type'=>Field::TYPE_TEXT)),
		self::TABLE.DOT.self::F_LANG_ID=> new Field($this,self::F_LANG_ID,self::TABLE,array(
				'auto'=>true,
				'lenght'=>2,
				'join_table'=>'lang'))		);
	}
	
	public function countParent($id){
			return $this->loadCount(array('where'=>DB::apostrof(self::F_PARENT_ID).'='.(int)$id));
	}
}
